#coding:utf8

from PyQt5.QtWidgets import *
from PyQt5.QtGui import *
from PyQt5.QtCore import *

from pynput import keyboard
import time
from pynput import mouse
import threading
import math
import sys, os, random
from collections import deque
import copy
import json

def cal_dis(pos, sp):
    dx = pos[0] - sp[0]
    dy = pos[1] - sp[1]
    return math.sqrt(dx*dx+dy*dy)

arrm = {1: [-1, 1],2: [0, 1],3: [1, 1],4: [-1, 0],6: [1, 0],7: [-1, -1],8: [0, -1],9: [1, -1],}
def get_arr(x, y):
    s = '↙↓↘←→↖↑↗'
    co = 0
    def same(a, b):
        if a == 0 and b == 0:
            return True
        if a > 0 and b > 0:
            return True
        if a < 0 and b < 0:
            return True
        return False
    
    for k, v in arrm.items():
        co += 1
        dx, dy = v
        if same(x, dx) and same(y, dy):
            return s[co-1]
    return '□' 

ss = '''
[["<96>", 96], ["<97>", 97], ["<98>", 98], ["<99>", 99], ["<100>", 100], ["<101>", 101], ["<102>", 102], ["<103>", 103], ["<104>", 104], ["<105>", 105],
["<110>", 110], ["'+'", 107], ["'-'", 109], ["'*'", 106], ["'/'", 111]]
'''

numL = json.loads(ss)

key_enter_time = 0
num_co = 0
def decode(key, pressed):
    global key_enter_time, num_co
    st = str(key)
    if 'Key.enter' in st:
        key_enter_time = time.time()
        return -2
    
    if '<255>' in st and time.time() - key_enter_time < 0.1:
        key_enter_time = 0
        return 15

    if st == 'Key.num_lock':
        if pressed:
            num_co += 1
        if num_co % 2 == 0:            
            return 16
        return -2
        
    if not hasattr(key, 'vk') :
        return -1

    if key.vk==107:
        return 11
    if key.vk==109:
        return 12
    if key.vk==106:
        return 13
    if key.vk==111:
        return 14
    for i in range(len(numL)):
        if numL[i] == [str(key), key.vk]:
            return i
    return -1

def deal_sum(sum, a, max_l):
    if len(sum) >= max_l:
        return sum
    if a == 0:
        if sum == '0':
            return sum
        sum += '0'
        return sum
    if a == 10:
        if '.' in sum:
            return sum
        sum += '.'
        return sum
    if sum == '0':
        sum = str(a)
        return sum
    sum += str(a)
    return sum

def is_ff(s):
    if '.' not in s:
        return False
    
    if s[-1]=='.':
        return True
    if '.' in s and s[-1]=='0':
        return True
    
def change_sum_10(s):
    if s=='0.':
        return True,0
    if s=='0.0':
        return False,0    
    if not is_ff(s):
        if len(s)>1 and '.' not in s:
            return True,float(s[0]+'.'+s[1])
        return True,float(s)
    if s[-1]=='.':
        return False,float(s[0]+'.'+s[1:-1])
    a,b = s.split('.')
    if b in '0'*10:
        x = b[0]+'.'+b[1:]+a
        return False,float(x)
    return False,float(s)

def change_sum(s):
    if s=='0.':
        return True,0
    if s=='0.0':
        return False,0    
    if not is_ff(s):
        return True,float(s)
    if s[-1]=='.':
        return False,float(s[:-1])
    a,b = s.split('.')
    x = b[0]+'.'+b[1:]+a
    if b in '0'*10:
        x = b[0]+'.'+b[1:]+a
        return False,float(x)
    return False,float(s)

if __name__ == '__main__':
    a = '123.0'
    print(change_sum(a),a)
    
